// 文件处理通用方法文件
import request from '@/utils/request'
import { Loading } from 'element-ui';

// 通用获取Blob文件流方法
export function getFileBlob(fileName) {
  return request({
    url: '/file/utils/download?fileUuid='+fileName,
    method: 'post',
    responseType: "blob"
  })
}

// 通用上传方法  form为FormData类型
export function uploadFile(url,form,method="post") {
return request({
  url,
  data:form,
  method,
  headers: {
      'Content-Type': 'multipart/form-data',
  }})
}

// 通用打印文件流方法
export function printPDFBlob(fileName) {
  const loading= Loading.service({
    lock: true,
    text: "文件加载中...",
    background: "#fff",
  });
  getFileBlob(fileName).then(blob=>{
    loading.close();
    let date = (new Date()).getTime()
    let ifr = document.createElement('iframe')
    ifr.style.frameborder = 'no'
    ifr.style.display = 'none'
    ifr.style.pageBreakBefore = 'always'
    ifr.setAttribute('id', 'printPdf' + date)
    ifr.setAttribute('name', 'printPdf' + date)
    ifr.src = window.URL.createObjectURL(blob)
    document.body.appendChild(ifr)
    document.getElementById('printPdf' + date).contentWindow.print();
    window.URL.revokeObjectURL(ifr.src)
}).catch(e=>{
  loading.close();
  console.log(e);
})
}
// 通用回影像查询接口
// 无pdf情况
export function currencyImageXDLR(data) {
    return request({
        url: '/operations-management/image/currency/query',
        method: 'post',
        data
    })
}
// 有pdf情况
export function currencyImage(data) {
    return request({
        url: '/operations-management/image/insurance/query',
        method: 'post',
        data
    })
}
